/*
 * @Date: 2022-02-14 15:05:35
 * @LastEditors: 春贰
 * @gitee: https://gitee.com/chun22222222
 * @github: https://github.com/chun222
 * @Desc:
 * @LastEditTime: 2023-11-28 10:45:30
 * @FilePath: \server\system\model\DbModel\sys.go
 */

package DbModel

import (
	"time"
)

//用户
type SysUser struct {
	LoginName         string          `json:"login_name" gorm:"primaryKey;size:100;not null;comment:登录名" binding:"required"`
	UserName          string          `json:"user_name"  gorm:"size:100"`
	Password          string          `json:"password" gorm:"size:255"` //密码为空则为第三方登录
	PassUpdate        *time.Time      `json:"pass_update" gorm:"comment:密码更新时间"`
	PassAvailableDays uint            `json:"pass_available_days" gorm:"comment:密码有效天数"`
	Status            int             `json:"status"` //1可用，2过期，3锁定
	Email             string          `json:"email"  gorm:"size:100"`
	Phone             string          `json:"phone"  gorm:"size:20"`
	Token             string          `json:"token"  gorm:"-"`
	Ip                string          `json:"ip"  gorm:"-"`
	Kick              uint            `json:"kick"  gorm:"-"` //99：强制登录,1：已经登录需要询问，0：直接可以登录
	Photo             string          `json:"photo"  gorm:"type:LONGTEXT;comment:头像"`
	RecognitionCode   string          `json:"recognition_code"  gorm:"type:LONGTEXT;comment:识别码"`
	Permissions       []SysPermission `json:"permissions" gorm:"many2many:sys_user_permission;joinForeignKey:UserName;joinReferences:PermissionName;"`
	Roles             []SysRole       `json:"-" gorm:"many2many:sys_user_role;joinForeignKey:UserName;joinReferences:RoleName;"`
	MenuRoleName      string          `json:"menu_role_id"  gorm:"-"`
	CreatedAt         time.Time       `json:"create_time" gorm:"column:create_time;comment:创建时间"` // 创建时间
	UpdatedAt         time.Time       `json:"update_time" gorm:"column:update_time;comment:更新时间"` // 更新时间
	//Powers      []SysPermission `json:"powers"  gorm:"-"`
}

type SysLoginLog struct {
	ID            uint      `json:"id" gorm:"primaryKey;autoIncrement"` // 主键ID
	UserId        uint      `json:"user_id" gorm:"column:user_id"`
	LoginName     string    `json:"login_name" gorm:"size:100;not null;comment:登录名"`
	UserName      string    `json:"user_name"  gorm:"size:100"`
	Status        int       `json:"status"`
	Msg           string    `json:"msg" gorm:"size:200"`
	Ip            string    `json:"ip"  gorm:"size:100"`
	Login         time.Time `json:"login" gorm:"column:login;comment:登陆时间"`
	Logout        time.Time `json:"logout" gorm:"column:logout;comment:登出时间"`
	OnlineSeconds float64   `json:"online_seconds" gorm:"column:online_seconds;comment:在线时长s"`
	LoginWay      uint      `json:"login_way" gorm:"column:login_way;comment:登陆方式"`
	CreatedAt     time.Time `json:"create_time" gorm:"column:create_time;comment:创建时间"` // 创建时间
}

//权限
type SysPermission struct {
	Name       string          `json:"name" gorm:"primaryKey;size:100;not null;comment:唯一标识"`
	Parent     string          `json:"parent" gorm:"default:0;comment:父级name"`
	Title      string          `json:"title" gorm:"size:100;comment:名称"`
	Path       string          `json:"path" gorm:"size:100;comment:页面路径"`
	Icon       string          `json:"icon" gorm:"size:100;comment:图标"`
	Sort       uint            `json:"sort" gorm:"default:99;comment:排序"`
	Type       string          `json:"type" gorm:"size:10;default:menu;comment:类型"`
	Status     uint            `json:"status" gorm:"default:0;comment:状态"`
	Isshowmenu uint            `json:"isshowmenu" gorm:"default:1;comment:是否菜单显示"`
	Isrecord   uint            `json:"isrecord" gorm:"default:2;comment:是否记录"`
	ScriptName string          `json:"script_name" gorm:"comment:脚本钩子"`
	Children   []SysPermission `json:"children" gorm:"-"`
	CreatedAt  time.Time       `json:"create_time" gorm:"column:create_time;comment:创建时间"` // 创建时间
	UpdatedAt  time.Time       `json:"update_time" gorm:"column:update_time;comment:更新时间"` // 更新时间
}

//用户权限关联表
type SysUserPermission struct {
	LoginName      string        `json:"login_name" gorm:"size:100;not null;comment:登录名"`
	PermissionName string        `json:"permission_name" gorm:"comment:权限"`
	Checked        uint          `json:"checked" gorm:"comment:状态：1为选中，0为半选中"`
	Permission     SysPermission `json:"permissions" gorm:"foreignKey:PermissionName;references:Name"`
}

//角色表
type SysRole struct {
	Name        string          `json:"name" gorm:"primaryKey;size:100;not null;comment:角色名称"`
	Desc        string          `json:"desc"  gorm:"size:255;comment:描述"`
	Permissions []SysPermission `json:"permissions" gorm:"many2many:sys_role_permission;joinForeignKey:RoleName;joinReferences:PermissionName;"`
	CreatedAt   time.Time       `json:"create_time" gorm:"column:create_time;comment:创建时间"` // 创建时间
	UpdatedAt   time.Time       `json:"update_time" gorm:"column:update_time;comment:更新时间"` // 更新时间
}

//用户权限角色
type SysUserRole struct {
	UserName string  `json:"user_name" gorm:"comment:用户id"`
	RoleName string  `json:"role_name" gorm:"comment:角色id"`
	Roles    SysRole `json:"roles" gorm:"foreignKey:RoleName;references:Name"`
}

//角色权限关联表
type SysRolePermission struct {
	RoleName       string        `json:"role_name" gorm:"comment:角色id"`
	PermissionName string        `json:"permission_name" gorm:"comment:权限id"`
	Checked        uint          `json:"checked" gorm:"comment:状态：1为选中，0为半选中"`
	Permission     SysPermission `json:"permissions" gorm:"foreignKey:PermissionName;references:Name"`
}

//日志表
type SysRecord struct {
	ID        uint      `json:"id" gorm:"primaryKey;autoIncrement"` // 主键ID
	Uid       uint      `json:"uid" gorm:"comment:用户id"`            // 用户id
	Username  string    `json:"username" gorm:"size:100;comment:用户名称"`
	Url       string    `json:"url" gorm:"size:100;comment:Url"`
	Desc      string    `json:"desc" gorm:"size:100;comment:描述"`
	Ip        string    `json:"ip" gorm:"size:30;comment:Ip"`
	Request   string    `json:"request" gorm:"size:1000;comment:请求"`
	CreatedAt time.Time `json:"create_time" gorm:"column:create_time;comment:创建时间"` // 创建时间
}

//系统配置表
type SysConfig struct {
	Name        string    `json:"name" gorm:"size:40;primaryKey;"` // 主键ID
	Desc        string    `json:"desc" gorm:"size:100;comment:描述"`
	Group       string    `json:"group" gorm:"size:100;comment:分组"`
	Type        uint      `json:"type" gorm:"comment:类型1：字符串 2 数字 3 数组 4 字典"`
	Value       string    `json:"value" gorm:"-"`
	ValueString string    `json:"value_string" gorm:"size:1000;comment:值字符串"`
	CreatedAt   time.Time `json:"create_time" gorm:"column:create_time;comment:创建时间"` // 创建时间
}
